﻿using System;
using ClientOverflow.Core;
using ClientOverflow.ViewModels.Interfaces;
using ClientOverflow.ViewModels.TagsViewModels;
using ClientOverflow.ViewModels.UserProfileViewModels;

namespace ClientOverflow.ViewModels.MainMenus
{
    /// <summary>
    /// ShowProfileCommand command sets the view to show user profile state. This command observes the ILoginService
    /// in order to set its state since this mode can be available only when a user is logged in.
    /// </summary>
    public class ShowTagsCommand : INamedCommand
    {
        private readonly IMenusViewModel viewModel;
        private readonly ILoginService loginService;

        public ShowTagsCommand(IMenusViewModel viewModel)
        {
            this.viewModel = viewModel;
            loginService = ServicesProviderFactory.GetInstance().LoginService;
            loginService.OnLoginChanged += (sender, args) => CanExecuteChanged(this, EventArgs.Empty);
        }

        public void Execute(object parameter)
        {
            viewModel.Content = new TagsViewModel(viewModel);
        }

        public bool CanExecute(object parameter)
        {
            return loginService.LoggenInUser != null;
        }

        public event EventHandler CanExecuteChanged;

        public string Name
        {
            get { return "Active tags"; }
        }
    }
}